//
//  XS_OrderDetailVC.swift
//  XueDao
//
//  Created by Mac on 2020/12/23.
//

import UIKit

class XS_OrderDetailVC: XS_BaseVC {

    @IBOutlet weak var bgImageView: UIImageView!
    @IBOutlet weak var statusBtn: QMUIButton!
    @IBOutlet weak var imgView: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var numberLabel: UILabel!
    @IBOutlet weak var priceLabel: UILabel!
    @IBOutlet weak var couponPriceLabel: UILabel!
    @IBOutlet weak var scorePriceLabel: UILabel!
    @IBOutlet weak var noLabel: UILabel!
    @IBOutlet weak var payTypeLabel: UILabel!
    @IBOutlet weak var payTimeLabel: UILabel!
    
    var model : XS_OrderItemModel = XS_OrderItemModel()
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        shouldNavBarHidden = true
        isStatusBarBlack = false
        loadCustomBar()
        statusBtn.imagePosition = .left
        statusBtn.spacingBetweenImageAndTitle = 12
        reloadData()
        
//        订单状态,未支付notpay 已支付pay 已取消 cancel
        if model.state == "notpay" {
            bgImageView.image = UIImage.init(named: "编组 5_1")
            statusBtn.setTitle("未支付", for: .normal)
            statusBtn.setImage(UIImage.init(named: "编组 9_2"), for: .normal)
        }else if model.state == "payment"{
            bgImageView.image = UIImage.init(named: "首页-证书背景")
            statusBtn.setTitle("购买成功", for: .normal)
            statusBtn.setImage(UIImage.init(named: "编组 9_1"), for: .normal)
        }else if model.state == "cancel"{
            bgImageView.image = UIImage.init(named: "编组 5-1")
            statusBtn.setTitle("购买失败", for: .normal)
            statusBtn.setImage(UIImage.init(named: "编组 9_1-1"), for: .normal)
        }
    }


    func reloadData(){
        imgView.sd_setImage(with: URL.init(string: model.curriculumImgUrl), completed: nil)
        titleLabel.text = model.curriculumName
        numberLabel.text = model.purchaseNumber + "人已加入学习"
        priceLabel.text = "￥"+model.payMoney
        if Int(model.couponMoney) != 0 {
            couponPriceLabel.text = "-"+model.couponMoney
        }else{
            couponPriceLabel.text = "无"
        }
        if Int(model.score) != 0 {
            scorePriceLabel.text = "-"+model.score
        }else{
            scorePriceLabel.text = "无"
        }
        noLabel.text = model.orderNo
        if model.payType == "money" {
            payTypeLabel.text = "余额"
        }
        if model.payType == "wechat" {
            payTypeLabel.text = "微信"
        }
        if model.payType == "aliapy" {
            payTypeLabel.text = "支付宝"
        }
        payTimeLabel.text = model.orderTime
    }
}
